package view;

import javax.swing.JTable;
import javax.swing.table.JTableHeader;
import javax.swing.table.TableModel;

public class SortedTable<T> extends JTable {

	/**
	 * 
	 */
	private static final long serialVersionUID = -8131308482851601064L;

	public SortedTable(AbstractResultadoModel<T> model) {
		this.setModel(model);
		JTableHeader header = this.getTableHeader();
		header.setUpdateTableInRealTime(true);
		header.addMouseListener(new HeaderListener<T>(this));
		header.setReorderingAllowed(true);
	}

	public void setModel(AbstractResultadoModel<T> model) {
		super.setModel(model);
	}

	public void setModel(TableModel dataModel) {
		if (dataModel.getClass().equals(AbstractResultadoModel.class)) {
			throw new RuntimeException("Solo se acepta modelos: "
					+ AbstractResultadoModel.class);
		}

	}

	@SuppressWarnings("unchecked")
	public AbstractResultadoModel<T> getModel() {
		return (AbstractResultadoModel<T>) super.getModel();
	}

}
